/**
 * 
 */
package com.myworld.config.mq.rocket.consumer;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

/** 
 * @ClassName: RocketMQConsumerConfiguration 
 * @Description: RocketMQ消费者bean注入
 * @author zhuqiang
 * @date 2018年12月29日 下午1:44:31 
 */
@SpringBootConfiguration //发送消息时注释掉该类
public class RocketMQConsumerConfiguration {
	public static final Logger loggger = LoggerFactory.getLogger(RocketMQConsumerConfiguration.class);
	@Value("${rocketmq.consumer.namesrvAddr}")
    private String namesrvAddr;
    @Value("${rocketmq.consumer.consumeThreadMin}")
    private int consumeThreadMin;
    @Value("${rocketmq.consumer.consumeThreadMax}")
	private int consumeThreadMax;
	
	//消费者consumerGroup
	@Value("${rocketmq.consumer.rockerJFConsumer.consumerGroup}")
	private String rockerJFConsumerGroup;
	
	/**
	* 消息消费者topic
	*/
	@Value("${rocketmq.consumer.rockerJFConsumer.topic}")
	private String rockerJFConsumerTopic;
	/**
     * 消息消费者tag
     */
    @Value("${rocketmq.consumer.rockerJFConsumer.tag}")
    private String rockerJFConsumerTag;
    /**
     * 日志消息监听器处理类
     */
    @Resource(name="jFMessagesListener")
    private JFMessagesListener jFMessagesListener;

	/**
     * 消费者bean
     * @return
     * @throws Exception
     */
    @Bean(name="rockerJFConsumer",initMethod="init",destroyMethod="destroy")
    public RockerJFConsumer getRockerJFConsumer() throws Exception {
        Object[] ps=new Object[]{rockerJFConsumerGroup,namesrvAddr,rockerJFConsumerTag,rockerJFConsumerTopic};
        loggger.info("###初始化rockerJFConsumer, consumerGroup:{}, namesrvAddr:{},  tag:{}, topic:{}",ps);
        RockerJFConsumer consumer=new RockerJFConsumer(rockerJFConsumerGroup, namesrvAddr,
                rockerJFConsumerTag, rockerJFConsumerTopic, jFMessagesListener,consumeThreadMin,consumeThreadMax);
        return consumer;
	    }

}
